{extend name="top/index" /}
{block name="main"}
	<!-- END SIDEBAR -->
	<!-- BEGIN CONTENT -->

	<div class="page-content-wrapper">
		<div class="page-content">
			<!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->
			<div class="modal fade" id="portlet-config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
							<h4 class="modal-title">Modal title</h4>
						</div>
						<div class="modal-body">
							 Widget settings form goes here
						</div>
						<div class="modal-footer">
							<button type="button" class="btn blue">Save changes</button>
							<button type="button" class="btn default" data-dismiss="modal">Close</button>
						</div>
					</div>
					<!-- /.modal-content -->
				</div>
				<!-- /.modal-dialog -->
			</div>
			<!-- /.modal -->
			<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
			<!-- BEGIN STYLE CUSTOMIZER -->
			<div class="theme-panel hidden-xs hidden-sm">
				<!-- <div class="toggler">
				</div> -->
				<div class="toggler-close">
				</div>
				<div class="theme-options">
					<div class="theme-option theme-colors clearfix">
						<span>
							 THEME COLOR
						</span>
						<ul>
							<li class="color-black current color-default" data-style="default">
							</li>
							<li class="color-blue" data-style="blue">
							</li>
							<li class="color-brown" data-style="brown">
							</li>
							<li class="color-purple" data-style="purple">
							</li>
							<li class="color-grey" data-style="grey">
							</li>
							<li class="color-white color-light" data-style="light">
							</li>
						</ul>
					</div>
					<div class="theme-option">
						<span>
							 Layout
						</span>
						<select class="layout-option form-control input-small">
							<option value="fluid" selected="selected">Fluid</option>
							<option value="boxed">Boxed</option>
						</select>
					</div>
					<div class="theme-option">
						<span>
							 Header
						</span>
						<select class="header-option form-control input-small">
							<option value="fixed" selected="selected">Fixed</option>
							<option value="default">Default</option>
						</select>
					</div>
					<div class="theme-option">
						<span>
							 Sidebar
						</span>
						<select class="sidebar-option form-control input-small">
							<option value="fixed">Fixed</option>
							<option value="default" selected="selected">Default</option>
						</select>
					</div>
					<div class="theme-option">
						<span>
							 Sidebar Position
						</span>
						<select class="sidebar-pos-option form-control input-small">
							<option value="left" selected="selected">Left</option>
							<option value="right">Right</option>
						</select>
					</div>
					<div class="theme-option">
						<span>
							 Footer
						</span>
						<select class="footer-option form-control input-small">
							<option value="fixed">Fixed</option>
							<option value="default" selected="selected">Default</option>
						</select>
					</div>
				</div>
			</div>
			<!-- END STYLE CUSTOMIZER -->
			<!-- BEGIN PAGE HEADER-->
			<div class="row">
				<div class="col-md-12">
					<!-- BEGIN PAGE TITLE & BREADCRUMB-->
					<h3 class="page-title">
					账户管理
					</h3>
					<ul class="page-breadcrumb breadcrumb">
						
						<li>
							<i class="fa fa-home"></i>
							<a href="{:url('index/index/index')}">
								Home
							</a>
							<i class="fa fa-angle-right"></i>
						</li>
						<li>
							<a href="{:url('index/manage/index')}">
								账户管理
							</a>
							<i class="fa fa-angle-right"></i>
						</li>
					</ul>
					<!-- END PAGE TITLE & BREADCRUMB-->
				</div>
			</div>
			
			<!-- END PAGE HEADER-->
			<!-- BEGIN PAGE CONTENT-->
			<div class="row">
				<div class="col-md-12">
					<!-- Begin: life time stats -->
					<div class="portlet">
						<div class="portlet-title">
							<div class="caption">
								<i class="fa fa-gift"></i>添加人员
							</div>
							
						</div>
						<div>
							  <div class="form-group">
							    <label for="exampleInputEmail1">用户名</label>
							    <input type="text" class="form-control" name="username" placeholder="用户名" required="required" id="username">
							  </div>
							  <div class="form-group">
							    <label for="exampleInputPassword1">密码</label>
							    <input type="password" class="form-control" name="pwd" placeholder="密码" required="required" id="pwd">
							  </div>
							  <div class="form-group">
							    <label for="exampleInputFile">确认密码</label>
							    <input type="password" class="form-control" name="repwd" placeholder="确认密码" required="required" id="repwd">
							  </div>
							  
							   <div class="form-group">
							    <label for="exampleInputFile">邮箱</label>
							    <input type="email" class="form-control" name="email" placeholder="邮箱" id="email">
							  </div>
							   <div class="form-group" style="width: 20%;">
							    <label for="exampleInputFile">组织单位</label>
							  	<select  class="form-control" name="zuzhi" id="zuzhi">
							  		<option value="-1">-请选择组织单位-</option>
							  		{volist name="org" id="vo"}
									
									<option value="{$vo.org_id}">{$vo.html}{$vo.org_name}{$vo.html}</option>
									{/volist}
							  	</select>
							  </div>
							  
							  <div class="form-group">
							    <label for="exampleInputFile">工作地点</label>
							    <input type="text" class="form-control" name="address" placeholder="工作地点" id="address">
							  </div>
							  <div class="form-group">
							    <label for="exampleInputFile">移动电话</label>
							    <input type="text" class="form-control" name="mobile" placeholder="移动电话" id="mobile">
							  </div>
							  <div class="form-group">
							    <label for="exampleInputFile">办公室电话</label>
							    <input type="text" class="form-control" name="omobile" placeholder="办公室电话" id="omobile">
							  </div>
							  <div class="form-group">
							    <label for="exampleInputFile">备注</label>
							    <input type="text" class="form-control" name="more" placeholder="备注" id="more">
							  </div>

							  <div class="form-group">
							    <label for="exampleInputFile" class="col-md-12" style="padding: 0;">类型</label>
						            <input type="radio" name="level" value="0" checked="" >普通人员
						            <input type="radio" name="level" value="1">领导
						      </div>
							  <button type="submit" class="btn btn-success">添加</button>
							  <a href="javascript:history.back(-1)" class="btn btn-primary">取消</a>

						</div>
					</div>
					<!-- End: life time stats -->
				</div>
			</div>

			<!-- END PAGE CONTENT-->
		</div>
	</div>
	<!-- END CONTENT -->
</div>
<!-- END CONTAINER -->
<!-- BEGIN FOOTER -->
<div class="footer">
	<div class="footer-inner">
		 2018 &copy; 仁聚科技
	</div>
	<div class="footer-tools">
		<span class="go-top">
			<i class="fa fa-angle-up"></i>
		</span>
	</div>
</div>
<link href="/static/assets/css/toastr.min.css" rel="stylesheet"/>
<script src="/static/assets/js/toastr.min.js" rel="stylesheet"/></script>
<script>
	$('#zuzhi').change(function(){
		var zuzhi = $('#zuzhi').val();
		//初始化下拉框
		$('#zu').empty();
		getZu(zuzhi);
	});
	function getZu(res){
            $.ajax({
                type:"POST",
                url:"{:url('index/Manage/getZu')}",
                data:{id:res}, 
                dataType:'json',
                success:function(data){
                	// console.log(data.length);
                	if (data.length != 0 ) {
                		$('#zu').removeAttr('disabled');
                		$('#zu').append('<option value="-1">请选择所属组</option>');
                		for (var i = 0 ; i < data.length; i++) {
                			$('#zu').append('<option value='+data[i]['org_id']+'>'+data[i]['org_name']+'</option>');
                		}
                	}else{
                		$('#zu').attr('disabled',true);
                	}
                },
                //Ajax请求超时，继续查询
                error:function(XMLHttpRequest,textStatus,errorThrown){
                   
                }
 
            });
        }
    $('#zu').change(function(){
		var zu = $('#zu').val();
		//初始化下拉框
		$('#zuzu').empty();
		// console.log(zu);
		getZuzu(zu);
	});
    function getZuzu(res){
            $.ajax({
                type:"POST",
                url:"{:url('index/Manage/getZu')}",
                data:{id:res}, 
                dataType:'json',
                success:function(data){
                	// console.log(data.length);
                	if (data.length != 0 ) {
                		$('#zuzu').removeAttr('disabled');
                		for (var i = 0 ; i < data.length; i++) {
                			$('#zuzu').append('<option value='+data[i]['org_id']+'>'+data[i]['org_name']+'</option>');
                		}
                	}else{
                		$('#zuzu').attr('disabled',true);
                	}
                },
                //Ajax请求超时，继续查询
                error:function(XMLHttpRequest,textStatus,errorThrown){
                   
                }
 
            });
        }
</script>
<script>
	$('.btn-success').click(function(){
		console.log($('#zuzhi').val());
		if($('#username').val() == ''){
			toastr.error('请填写用户名');
		}else if($('#username').val() == 'admin'){
			toastr.error('该用户名已存在');
		}else if($('#pwd').val() == ''){
			toastr.error('请填写密码');
		}else if($('#repwd').val() == ''){
			toastr.error('请填写确认密码');
		}else if($('#pwd').val() != $('#repwd').val() ){
			toastr.error('两次密码填写不一致');
		}else if($('#zuzhi').val() == '-1'){
			toastr.error('请选择组织单位');
		}else{
			postdata();
		}
	});
	function postdata()
	{
		$.ajax({
                type:"POST",
                url:"{:url('index/Register/doRegister')}",
                data:{
                	username : $('#username').val(),
                	pwd : $('#pwd').val(),
                	repwd : $('#repwd').val(),
                	email : $('#email').val(),
                	zuzhi : $('#zuzhi').val(),
                	zu : $('#zu').val(),
                	zuzu : $('#zuzu').val(),
                	address : $('#address').val(),
                	mobile : $('#mobile').val(),
                	omobile : $('#omobile').val(),
                	more : $('#more').val(),
                	level : $('input:radio:checked').val()
                }, 
                dataType:'json',
                success:function(data){
                	console.log(data);
                	if (data) {
			            toastr.success('创建成功');
			            setInterval(function(){
			              location.href = "{:url('index/Manage/index')}";
			            }, 2000);
			          }else{
			            toastr.error('用户名已存在，请重试');
			          }
                },
                //Ajax请求超时，继续查询
                error:function(XMLHttpRequest,textStatus,errorThrown){
                   
                }
 
            });
	}
</script>
<!-- END JAVASCRIPTS -->
<script>
		$(function(){
			$('.manage').addClass("active");
		});
</script>
</body>
<!-- END BODY -->
</html>
{/block}
